<?php

namespace app\admin\model\user\party;

use think\Model;


class Partybranch extends Model
{





    // 表名
    protected $name = 'user_party_member';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'zjoining_time_text',
        'party_application_time_text',
        'party_active_time_text',
        'party_volunteer_time_text',
        'party_develop_time_text',
        'party_member_time_text',
        'preparatory_expiration_time_text',
        'create_time_text',
        'update_time_text',
        'status_text',
        'type_text',
    ];



    public function getStatusList()
    {
        return ['0' => __('待审核'), '1' => __('审核通过'), '2' => __('审核未通过')];
    }
    public function getTypeList()
    {
        return ['2' => __('预备党员'), '3' => __('党的发展对象'), '4' => __('入党积极分子'), '5' => __('入党申请人'), '6' => __('普通成员')];
    }


    public function getZjoiningTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['zjoining_time']) ? $data['zjoining_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getPartyApplicationTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['party_application_time']) ? $data['party_application_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getPartyActiveTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['party_active_time']) ? $data['party_active_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getPartyVolunteerTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['party_volunteer_time']) ? $data['party_volunteer_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getPartyDevelopTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['party_develop_time']) ? $data['party_develop_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getPartyMemberTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['party_member_time']) ? $data['party_member_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getPreparatoryExpirationTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['preparatory_expiration_time']) ? $data['preparatory_expiration_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    protected function setZjoiningTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPartyApplicationTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPartyActiveTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPartyVolunteerTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPartyDevelopTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPartyMemberTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setPreparatoryExpirationTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id')->setEagerlyType(0);
    }

    public function userinfo()
    {
        return $this->belongsTo('app\admin\model\user\Userinfo', 'user_id', 'user_id')->setEagerlyType(0);
    }
}
